package com.dao;

import com.entity.TD_Team;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

public interface TeamDao extends JpaRepository<TD_Team,Integer> {

    /**
     * 根据分类id查询该分类的所有新闻的id、标题、简略、标题图
     * @param typeId 分类id
     * @return   0=新闻id，1=标题，2=简略，3=标题图
     */
    @Query(value = "select fd_id,FD_Abbrev,FD_DESC,FD_NewsImg from TD_Team where Fd_newsimgtype=0 AND fd_TypeId=? order by FD_NewTime DESC ",nativeQuery = true)
    public List<Object[]> getTitleByFd_TypeId(int typeId, Pageable pageable);

    /**
     * 根据分类id查询该分类的所有轮播新闻
     * @param typeId 分类id
     * @return 0=新闻id，1=标题，2=标题图
     */
    @Query(value = "select fd_id,fd_Abbrev,fd_NewsImg from TD_Team where fd_newsimgtype=1 and fd_TypeId=?",nativeQuery = true)
    public List<Object[]> getLunBo(int typeId);

    /**
     * 获取新闻详情
     * @param id 新闻di
     * @return
     */
    @Query(value = "select * from TD_Team  where fd_ID=?",nativeQuery = true)
    public TD_Team getDetail(int id);

    /**
     * 根据父分类节点id获取所有子节点的滚动新闻
     * @param fatherType 父节点id
     * @return  0=id    1=图片
     */
    @Query(value = "SELECT\n" +
            "\ta.FD_ID,\n" +
            "\ta.FD_NewsImg\n" +
            "FROM\n" +
            "\tTD_Team a,\n" +
            "\tTD_NewsType b\n" +
            "WHERE\n" +
            "\ta.FD_TypeId = b.FD_TypeId\n" +
            "AND b.FD_FatherLevelID = ?\n" +
            "AND a.Fd_newsimgtype = 1",nativeQuery = true)
    public List<Object[]> getRollByFatherType(int fatherType);

    /**
     * 分类查询新闻并按照创建时间从高到低排序
     * @param typeId 分类id
     * @param pageable
     * @return
     */
    @Query(value = "select fd_id,FD_Abbrev,FD_NewTime,FD_NewsImg from TD_Team a where a.fd_TypeId=? ORDER BY a.FD_NewTime desc",nativeQuery = true)
    public List<Object[]> getTypeByCreateTimeDesc(int typeId,Pageable pageable);
}
